package reference;

import java.lang.ref.WeakReference;

/**
 * @author: 李德才
 * @description:
 * @create: 2020-12-13 16:14
 **/

public class Test_WeakReference {

    /**
     * 只要遭遇到 GC ，他就会被干掉
     */
    public static void main(String[] args) {
        WeakReference<M> m = new WeakReference<>(new M());

        System.out.println(m.get());
        System.gc();
        System.out.println(m.get());

        ThreadLocal<M> tl = new ThreadLocal<>();
        tl.set(new M());
        tl.remove();

    }

}
